
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
    <title>ambient.create_nc_db &#8212; Texas A&amp;M Oil spill / Outfall Calculator 2.1.0 documentation</title>
    <link rel="stylesheet" href="../../_static/alabaster.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
    <script src="../../_static/jquery.js"></script>
    <script src="../../_static/underscore.js"></script>
    <script src="../../_static/doctools.js"></script>
    <script src="../../_static/language_data.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="ambient.fill_nc_db" href="ambient.fill_nc_db.html" />
    <link rel="prev" title="ambient.Profile.get_values" href="ambient.Profile.get_values.html" />
   
  <link rel="stylesheet" href="../../_static/custom.css" type="text/css" />
  
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />

  </head><body>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  <div class="section" id="ambient-create-nc-db">
<h1>ambient.create_nc_db<a class="headerlink" href="#ambient-create-nc-db" title="Permalink to this headline">¶</a></h1>
<dl class="function">
<dt id="ambient.create_nc_db">
<code class="sig-prename descclassname">ambient.</code><code class="sig-name descname">create_nc_db</code><span class="sig-paren">(</span><em class="sig-param">nc_file</em>, <em class="sig-param">summary</em>, <em class="sig-param">source</em>, <em class="sig-param">sea_name</em>, <em class="sig-param">p_lat</em>, <em class="sig-param">p_lon</em>, <em class="sig-param">p_time</em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/ambient.html#create_nc_db"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#ambient.create_nc_db" title="Permalink to this definition">¶</a></dt>
<dd><p>Create an empty netCDF4-classic dataset to store ambient data</p>
<p>Creates an netCDF dataset file in netCDF4-classic format for use in 
storing ambient profile data.  This function creates the minimum data
structure necessary to run the TAMOC simulation models.  This includes 
temperature, salinity, and pressure as a function of depth, as well as
the auxiliary metadata, such as latitude, longitude, and time, etc.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>nc_file</strong><span class="classifier">file path or string</span></dt><dd><p>File name (supplied as a path or string) to use to create the netCDF
database</p>
</dd>
<dt><strong>summary</strong><span class="classifier">string</span></dt><dd><p>String containing the text for the dataset global variable <cite>summary</cite>.
This should describe the TAMOC simulation project for which the 
dataset was created.</p>
</dd>
<dt><strong>source</strong><span class="classifier">string</span></dt><dd><p>String containing the text for the dataset global variable <cite>source</cite>.
Use this variable to document the original source of the data (e.g., 
station BM54 recorded by R/V Brooks McCall).</p>
</dd>
<dt><strong>sea_name</strong><span class="classifier">string</span></dt><dd><p>String containing the NODC Sea Name.  If unsure, consult the list 
at <a class="reference external" href="http://www.nodc.noaa.gov/General/NODC-Archive/seanamelist.txt">http://www.nodc.noaa.gov/General/NODC-Archive/seanamelist.txt</a></p>
</dd>
<dt><strong>p_lat</strong><span class="classifier">float</span></dt><dd><p>Latitude of the CTD profile location in decimal degrees from North</p>
</dd>
<dt><strong>p_lon</strong><span class="classifier">float</span></dt><dd><p>Longitude of the CTD profile location in decimal degrees from East</p>
</dd>
<dt><strong>p_time :</strong></dt><dd><p>Time the profile was taken in seconds since 1970-01-01 00:00:00 0:00
following a julian calendar.  See Examples section for how to create
this variable using Python’s <cite>datetime</cite> module and the netCDF4 modules
<cite>netCDF4.date2num</cite> and <cite>netCDF4.num2date</cite>.</p>
</dd>
</dl>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><dl>
<dt><strong>nc</strong><span class="classifier"><cite>netCDF4.Dataset</cite> object</span></dt><dd><p>An object that contains the empty database ready to input profile data</p>
</dd>
</dl>
</dd>
</dl>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><code class="xref py py-obj docutils literal notranslate"><span class="pre">netCDF4</span></code></dt><dd></dd>
</dl>
</div>
<p class="rubric">Notes</p>
<p>This function creates an empty netCDF dataset that conforms to the 
standard format for an Orthogonal Multidimensional Array Representation 
of Profiles as defined by the National Oceanographic Data Center (NODC).  
See <a class="reference external" href="http://www.nodc.noaa.gov/data/formats/netcdf">http://www.nodc.noaa.gov/data/formats/netcdf</a> for more details.</p>
<p>NODC recommends using a netCDF4-classic data format, which does not 
support groups.  This works well for this dataset, so we implement this
data format here.  The documentation for the Python <cite>netCDF4</cite> package
here <a class="reference external" href="https://code.google.com/p/netcdf4-python/">https://code.google.com/p/netcdf4-python/</a> uses groups throughout 
the tutorial.  The classic format is equivalent to having the single 
group <cite>root_grp</cite>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span><span class="p">,</span> <span class="n">timedelta</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">netCDF4</span> <span class="kn">import</span> <span class="n">num2date</span><span class="p">,</span> <span class="n">date2num</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nc_file</span> <span class="o">=</span> <span class="s1">&#39;./test/output/test.nc&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">summary</span> <span class="o">=</span> <span class="s1">&#39;Test file&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">source</span> <span class="o">=</span> <span class="s1">&#39;None&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sea_name</span> <span class="o">=</span> <span class="s1">&#39;No Sea Name&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p_lat</span> <span class="o">=</span> <span class="mf">28.5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p_lon</span> <span class="o">=</span> <span class="mf">270.7</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p_time</span> <span class="o">=</span> <span class="n">date2num</span><span class="p">(</span><span class="n">datetime</span><span class="p">(</span><span class="mi">2010</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">30</span><span class="p">),</span> 
<span class="go">        units = &#39;seconds since 1970-01-01 00:00:00 0:00&#39;, </span>
<span class="go">        calendar = &#39;julian&#39;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nc</span> <span class="o">=</span> <span class="n">create_nc_db</span><span class="p">(</span><span class="n">nc_file</span><span class="p">,</span> <span class="n">summary</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span> <span class="n">sea_name</span><span class="p">,</span> <span class="n">p_lat</span><span class="p">,</span> 
<span class="go">        p_lon, p_time)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span>
<span class="go">OrderedDict([(&#39;time&#39;, &lt;netCDF4.Variable object at 0x76f2978&gt;), </span>
<span class="go">             (&#39;lat&#39;, &lt;netCDF4.Variable object at 0x76f2a98&gt;), </span>
<span class="go">             (&#39;lon&#39;, &lt;netCDF4.Variable object at 0x76f2ae0&gt;), </span>
<span class="go">             (&#39;z&#39;, &lt;netCDF4.Variable object at 0x76f2b28&gt;), </span>
<span class="go">             (&#39;temperature&#39;, &lt;netCDF4.Variable object at 0x76f2b70&gt;), </span>
<span class="go">             (&#39;salinity&#39;, &lt;netCDF4.Variable object at 0x76f2bb8&gt;), </span>
<span class="go">             (&#39;pressure&#39;, &lt;netCDF4.Variable object at 0x76f2c00&gt;)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span> <span class="n">num2date</span><span class="p">(</span><span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> 
<span class="go">        units = &#39;seconds since 1970-01-01 00:00:00 0:00&#39;, </span>
<span class="go">        calendar = &#39;julian&#39;)</span>
<span class="go">2010-05-30 00:00:00</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z_data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linspace</span><span class="p">(</span><span class="mf">0.</span><span class="p">,</span> <span class="mf">1500.</span><span class="p">,</span> <span class="mf">30.</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;z&#39;</span><span class="p">][:]</span> <span class="o">=</span> <span class="n">z_data</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;z&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">valid_max</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">z_data</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;z&#39;</span><span class="p">]</span>
<span class="go">float64 z(u&#39;z&#39;,)</span>
<span class="go">    long_name: depth below the water surface</span>
<span class="go">    standard_name: depth</span>
<span class="go">    units: m</span>
<span class="go">    axis: Z</span>
<span class="go">    positive: down</span>
<span class="go">    valid_min: 0.0</span>
<span class="go">    valid_max: 1500.0</span>
<span class="go">unlimited dimensions = (u&#39;z&#39;,)</span>
<span class="go">current size = (30,)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nc</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

</div>


          </div>
          
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="../../index.html">Texas A&M Oil spill / Outfall Calculator</a></h1>








<h3>Navigation</h3>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="../../user_manual.html">TAMOC User Manual</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../unit_tests.html">Unit Tests</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary.html">Glossary</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../bugs.html">Reporting Bugs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../readme.html">Read Me File</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../release.html">Release Notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../license.html">License</a></li>
</ul>

<div class="relations">
<h3>Related Topics</h3>
<ul>
  <li><a href="../../index.html">Documentation overview</a><ul>
  <li><a href="../../user_manual.html">TAMOC User Manual</a><ul>
  <li><a href="../../modules/ambient.html">Overview of Ambient Module</a><ul>
      <li>Previous: <a href="ambient.Profile.get_values.html" title="previous chapter">ambient.Profile.get_values</a></li>
      <li>Next: <a href="ambient.fill_nc_db.html" title="next chapter">ambient.fill_nc_db</a></li>
  </ul></li>
  </ul></li>
  </ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>








        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="footer">
      &copy;2020, Scott A. Socolofsky.
      
      |
      Powered by <a href="http://sphinx-doc.org/">Sphinx 2.4.4</a>
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
      
      |
      <a href="../../_sources/autodoc/ambient/ambient.create_nc_db.rst.txt"
          rel="nofollow">Page source</a>
    </div>

    

    
  </body>
</html>